<template>
  <div>
    <div class="head">
      <van-icon name="home-o" size='24' class="left" @click="$router.push('/index')"/>
      <h3>购物车</h3>
    </div>
    <div class="center">
      <p>您的购物车还是空的</p>
      <button>看看收藏</button>
      <button>去逛逛</button>
    </div>
    <ul>
      <h4>-为您推荐-</h4>
      <li v-for="data in goodslist" :key="data.productId" @click="todetail(data)">
        <img :src="data.productImg" alt />
        <div class="title">
          <p>{{data.productTitle}}</p>
        </div>
        <span class="xj">￥{{data.sellPrice}}</span>
        <span class="yj">￥{{data.originalPrice}}</span>
      </li>
    </ul>
  </div>
</template>
<script>
import axios from 'axios'
import { Icon, Tab, Tabs } from 'vant'
import 'swiper/css/swiper.css'
import Vue from 'vue'
Vue.use(Tab)
Vue.use(Tabs)
Vue.use(Icon)
export default {
  data() {
    return {
      goodslist: []
    }
  },
  mounted() {
    axios.get('/recommend/cart?currentPage=1&_=1583589190613'
    ).then(res=>{
      this.goodslist=res.data.data
      console.log(this.goodslist)
    })
  },
  methods: {
    todetail (data) {
      this.$router.push(`/item/${data.productId}`)
      this.$store.commit('setDataList',data)
    } 
  }
}
</script>
<style lang="scss" scoped>
.head{
    height: 44px;
    background: #ffffff;
    line-height: 44px;
    box-sizing: border-box;
    position: relative;
    padding: 0 10px;
    border-bottom: 1px solid #f5f5f5;
    h3{
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%,-50%);
      font-size: 17px;
    }
    .left{
      position: absolute;
      left: 10px;
      top: 12px
    }
}
.center{
  background: #f5f5f5;
  height: 90px;
  width: 100%;
  text-align: center;
  line-height: 40px;
  button{
    background: yellow;
    height: 40px;
    width: 80px;
    margin: 0 5px;
  }
}
ul {
  width: 100%;
  height: auto;
  overflow: hidden;
  h4{
    height: 60px;
    line-height: 60px;
    text-align: center;
  }
  li{
    box-sizing: border-box;
    height: 240px;
    width: 50%;
    float: left;
    padding: 10px;
    border: 1px solid #eee;
    img{
      height: 164px;
    }
    p{
      overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .yj{
      text-decoration:line-through;
      color: #aaa;
      font-size: 12px;
    }
  }
}
</style>
